//
//  SSNewOrderCell.swift
//  拾舍清洁
//
//  Created by sky.wei on 2023/6/26.
//

import UIKit

class SSNewOrderCell: UITableViewCell {
    var resultClosure: SSResultClosure?     // 闭包
    
    @IBOutlet weak var numberLab: UILabel!
    
    @IBOutlet weak var titleLab: UILabel!
    
    @IBOutlet weak var addressLab: UILabel!
    
    @IBOutlet weak var timeLab: UILabel!
    
    @IBOutlet weak var statusLab: UILabel!
    
    @IBOutlet weak var priceLab: UILabel!
    
    @IBOutlet weak var pushBtn: UIButton!
    
    @IBOutlet weak var checkoutBtn: UIButton!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    var model:SSEmployeeOrder = SSEmployeeOrder()  {
        didSet{
            titleLab.text = model.itemNames
            numberLab.text = "订单编号：\(model.orderNo)"
            addressLab.text = "服务地址：\(model.serviceAddr)"
            timeLab.text = "服务时间：\(model.serviceTime)"
            statusLab.text = model.status
            priceLab.text = "待付款：$\(model.pendingMoney)"
            pushBtn.isHidden = true
            
            checkoutBtn.isHidden = true
            checkoutBtn.isUserInteractionEnabled = false
            
            if((model.serviceType == "2") || (model.serviceType == "3")){//2tuifang 3shendu
                checkoutBtn.isHidden = false
                checkoutBtn.isUserInteractionEnabled = true
                checkoutBtn.setTitle("工作内容调整", for: .normal)
            }
            
            if(model.isExam == "1"){
                checkoutBtn.setTitle("员工检查", for: .normal)
                checkoutBtn.isHidden = false
                checkoutBtn.isUserInteractionEnabled = true
            }
            
            
            if(model.status == "2"){
                pushBtn.setTitle("开始打卡", for: .normal)
                statusLab.text = "待服务"
                statusLab.textColor = UIColor(hex: "#2475FF")
                pushBtn.isHidden = false
            }else if(model.status == "5"){
                statusLab.text = "服务中"
                statusLab.textColor = UIColor(hex: "#54C959")
                pushBtn.setTitle("结束打卡", for: .normal)
                pushBtn.isHidden = false
            }else if(model.status == "3"){
                statusLab.text = "已完成"
                statusLab.textColor = UIColor(hex: "#E95515")
            }else if(model.status == "7"){
                statusLab.text = "待通过"
                statusLab.textColor = UIColor(hex: "#54C959")
            }else if(model.status == "10"){
                statusLab.text = "待评价"
                statusLab.textColor = UIColor(hex: "#54C959")
            }else if(model.status == "4"){
                statusLab.text = "已取消"
                statusLab.textColor = UIColor(hex: "#E95515")
            }
            else{
                statusLab.text = "未知"
                statusLab.textColor = UIColor(hex: "#2475FF")
            }
        }
    }
    
    @IBAction func checkOutAction(_ sender: Any) {
        
        if(model.isExam == "1"){//jiancha
            let url  = "http://www.tenhousecleaning.com/clean-h5/emp-exam?orderNo=\(model.orderNo)&&phoneNo=\(kUserPhone)"
            let vc = SSWebViewController()
            vc.webUrl = url
            UIViewController.current().navigationController?.pushViewController(vc, animated: true)
            return
        }
        
        if(model.serviceType == "2" || (model.serviceType == "3")){
            let vc = SSWorkContentController()
            vc.orderNum = model.orderNo
            UIViewController.current().navigationController?.pushViewController(vc, animated: true)
        }
        
       
   
    }
    
    @IBAction func pushAction(_ sender: Any) {
        
        let vc = WeChatMomentDemoViewController()
        vc.orderNo = model.orderNo
        vc.resultClosure {
            self.resultClosure!()
        }
//        vc.title = "开始打卡"
//        UIViewController.current().navigationController?.pushViewController(vc, animated: true)
        if(model.status == "2"){
            vc.title = "开始打卡"
            vc.type = "1"
            UIViewController.current().navigationController?.pushViewController(vc, animated: true)
        }else if(model.status == "5"){
            vc.title = "结束打卡"
            vc.type = "2"
            UIViewController.current().navigationController?.pushViewController(vc, animated: true)
        }
    }
    
    func resultClosure(_ finished: @escaping SSResultClosure) {
        resultClosure = finished
    }
    
}

